# -*- coding: utf-8 -*-
import hashlib
def md5digest(number, encoding='utf-8'):
    '''
    a simple funtion to compute md5 hash code for numbers
    '''
    string = str(number)
    hashed = hashlib.md5()
    hashed.update(string.encode(encoding))
    return hashed.hexdigest()

if __name__ == "__main__":
    import sys
    if len(sys.argv) != 2:
        print("usage: python md5_hash.py <input_filename>")
        sys.exit(0)
    # read lines and compute md5 hash
    print('read file {} ...'.format(sys.argv[1]))
    with open(sys.argv[1],'r') as fp:
        lines = fp.readlines()
        lines = [line.strip() for line in lines]
        lines = [md5digest(line) + '\n' for line in lines]
    # write it to md5_output.txt
    print("write output as `md5_output.txt` ...")
    with open("md5_output.txt", "w") as fp:
        fp.writelines(lines)

